<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="客户名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户编号" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入开票名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="地区" prop="area">
        <el-select v-model="queryParams.area" placeholder="请选择所属地区" clearable>
          <el-option v-for="dict in dict.type.order_area" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['develop:GoodsCustomer:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="showUploadDialog">导入</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>





      <!--<el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                  @click="handleUpdate" v-hasPermi="['develop:GoodsCustomer:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
          <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
              <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                         v-hasPermi="['develop:GoodsCustomer:remove']">删除</el-button>
          </el-popconfirm>
      </el-col>
      <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini"
                  @click="handleExport" v-hasPermi="['develop:GoodsCustomer:export']">导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
      :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="80" />
      <el-table-column align="center" label="地区" prop="area" sortable>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_area" :value="scope.row.area" />
        </template>
      </el-table-column>
      <el-table-column label="客户编码" align="center" prop="code" sortable />
      <el-table-column label="客户名称" align="center" prop="name" width="300" show-overflow-tooltip sortable />
      <el-table-column label="联系人" align="center" prop="linkMan" sortable />
      <el-table-column label="电话" align="center" prop="tel" sortable />
      <el-table-column label="打款税号" align="center" prop="taxNo" sortable />
      <el-table-column label="开户行" align="center" prop="bankName" show-overflow-tooltip sortable />
      <el-table-column label="银行账号" align="center" prop="bankNo" sortable />
      <el-table-column label="地址" align="center" prop="addr" show-overflow-tooltip sortable />
      <el-table-column label="备注信息" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['develop:GoodsCustomer:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除 `+scope.row.name+` 数据项？`" @confirm="handleDelete(scope.row)"
            style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
              v-hasPermi="['develop:GoodsCustomer:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <upload-dialog ref="uploadDialog" @ok="getList" @handleFileSuccess="handleFileSuccess"></upload-dialog>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <goodsCustomer-form ref="form" @ok="getList"></goodsCustomer-form>
  </div>
</template>

<script>
import {deleteAction, downloadFile,getAction} from '@/api/manage'
  import GoodsCustomerForm from '@/views/develop/goodsCustomer/module/GoodsCustomerForm'
  import UploadDialog from "@/views/upload/UploadDialog";

  export default {
    name: "GoodsCustomerList",
    dicts: ['order_area'],
    components: {
      GoodsCustomerForm,
      UploadDialog
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 客户信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          code: null,
          name: null,
          area: null,
          taxNo: null,
          addr: null,
          tel: null,
          bankName: null,
          bankNo: null,
          info: null,
          status: null,
          orderByColumn: 'create_time',
          isAsc: 'desc'
        },
        url: {
          list: '/goodsCustomer/goodsCustomer/list',
          remove: '/goodsCustomer/goodsCustomer/',
          export: '/goodsCustomer/goodsCustomer/export',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询客户信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },

      handleFileSuccess(response, file, fileList) {
        this.$refs.uploadDialog.open = false;
        this.$refs.uploadDialog.isUploading = false;
        if (response.data.code == "200") {
          this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data
            .errorText, "导入结果", {
              dangerouslyUseHTMLString: true
            });
        } else {
          this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data
            .errorText, "导入结果", {
              dangerouslyUseHTMLString: true
            });
        }
        this.getList();
      },
      showUploadDialog() {
        this.$refs.uploadDialog.title = "信息导入";
        this.$refs.uploadDialog.tmplName = "客户信息模板.xlsx";
        this.$refs.uploadDialog.fileName = "客户信息.xlsx";
        this.$refs.uploadDialog.uploadUrl = "/goodsCustomer/goodsCustomer/importData";
        this.$refs.uploadDialog.show();
      },

      /** 导出按钮操作 */
      handleExport() {
        downloadFile(this.url.export, this.queryParams);
      },


    }
  };
</script>
